package com.mxgraph.confluence.plugins.util;
import com.atlassian.confluence.license.LicenseService;
import com.atlassian.upm.api.license.PluginLicenseManager;

public class DrawioLicenseManager {
    private PluginLicenseManager pluginLicenseManager;
    private LicenseService licenseService;

    public DrawioLicenseManager(PluginLicenseManager pluginLicenseManager, LicenseService licenseService) {
        this.pluginLicenseManager = pluginLicenseManager;
        this.licenseService = licenseService;
    }

    public boolean isDevLicense() {
        /*try {
            LicenseType lt = this.licenseService.retrieve().getLicenseType();
            return lt.compareTo(LicenseType.DEVELOPER) == 0 || lt.compareTo(LicenseType.TESTING) == 0;
        } catch (Throwable var2) {
            return false;
        }*/

        return false;
    }

    public DrawioLicenseManager.LicenseStatus getLicenseStatus() {
        /*Option<PluginLicense> licOpt = this.pluginLicenseManager.getLicense();
        if (this.isDevLicense()) {
            return DrawioLicenseManager.LicenseStatus.OK;
        } else if (!licOpt.isDefined()) {
            return DrawioLicenseManager.LicenseStatus.NO_LICENSE;
        } else {
            PluginLicense license = (PluginLicense)licOpt.get();
            if (license.isEvaluation()) {
                DateTime evalExpDate = (DateTime)license.getExpiryDate().get();
                return evalExpDate.isBefore(DateTime.now().minusWeeks(1)) ? DrawioLicenseManager.LicenseStatus.EVAL_EXPIRED : DrawioLicenseManager.LicenseStatus.EVAL_LICENSE;
            } else {
                if (license.getError().isDefined()) {
                    if (((LicenseError)license.getError().get()).equals(LicenseError.USER_MISMATCH)) {
                        return DrawioLicenseManager.LicenseStatus.USER_MISMATCH;
                    }
                    if (((LicenseError)license.getError().get()).equals(LicenseError.VERSION_MISMATCH)) {
                        return DrawioLicenseManager.LicenseStatus.VERSION_MISMATCH;
                    }
                }
                return DrawioLicenseManager.LicenseStatus.OK;
            }
        }*/

        return DrawioLicenseManager.LicenseStatus.OK;
    }

    public static enum LicenseStatus {
        NO_LICENSE,
        EVAL_LICENSE,
        EVAL_EXPIRED,
        USER_MISMATCH,
        VERSION_MISMATCH,
        OK;

        private LicenseStatus() {
        }
    }

}
